# this scripts lets you customise a downloaded iso from ubuntu



isolocation=/cdrom
version=14.04.1
### isofile is the iso file downloaded from ubuntu

#isoFile=$isolocation/ubuntu-$version-desktop-amd64.iso 
isoFile=$1
isolocation=$2
########## continue customising

isoMountPath=$isolocation/tmp/isoMount
squashfsFile=$isoMountPath/casper/filesystem.squashfs
squashfsMount=$isolocation/tmp/edit.delete
writeFolder=$isolocation/write.delete
readFolder=$isolocation/read.delete
newFolder=$isolocation/new.delete


echo if you would like to remove previous changes delete $writeFolder exit now, enter to continue
read x

#sudo rm -fr  $squashfsMount/* $isoMountPath/* $writeFolder/*
#sudo rmdir  $squashfsMount $isoMountPath $writeFolder

sudo mkdir -p $squashfsMount
sudo mkdir -p $isoMountPath
sudo mkdir -p $writeFolder
sudo mkdir -p $newFolder

. 0mountIso-isofile-path $isoFile $isoMountPath

. 1squashfsRWmountToFolder-squashfs-mountpoint-writefolder $squashfsFile $squashfsMount $writeFolder $readFolder

sudo cp git-setup $squashfsMount/

. 2editLiveCD-livecdpath $squashfsMount

echo now creating the squashfs, enter to confirm or exit

read x

sudo rm $newFolder/filesystem.*

. 5createSquashFs-source-destination $squashfsMount $newFolder


newcd=$isolocation/newcd
ncdmount=$newcd/mount
ncdtemp=$newcd/temp
ncdread=$newcd/read

sudo mkdir -p $ncdmount
sudo mkdir -p $ncdtemp
sudo mkdir -p $ncdread

sudo mount $isofile $ncdread
sudo mount -t overlayfs -o lowerdir=$ncdread,upperdir=$ncdtemp overlayfs $ncdmount

sudo cp $newFolder/* $ncdmount/casper/


IMAGE=$newcd/custom.iso
sudo rm $IMAGE
BUILD=$ncdmount

echo ready for buidling iso in $BUILD
read x
read x
read x

sudo mkisofs -r -V "Custom Ubuntu Install CD" \
            -cache-inodes \
            -J -l -b isolinux/isolinux.bin \
            -c isolinux/boot.cat -no-emul-boot \
            -boot-load-size 4 -boot-info-table \
            -o $IMAGE $BUILD


ls -al $IMAGE

echo check before umount
read x
read x

sudo umount $ncdmount
sudo umount $ncdread

sudo umount $squashfsMount
sudo umount $readFolder
sudo umount $isoMountPath
